#include <string>
#include <sstream>

#include <LengthUnit.h>
#include <CascadeFormate.h>

using namespace std;
LengthUnit CascadeFormate::lengthUnits_m[] = {MILE, YARD, FEET, INCH};

string CascadeFormate::formate(int baseValue) const
{
        ostringstream os;

	for (int i = 0; baseValue != 0 && i < sizeof(lengthUnits_m)/sizeof(LengthUnit); i++) {

		int number = lengthUnits_m[i].covertFromBaseUnit(baseValue);			
		os << lengthUnits_m[i].formate(number);
		baseValue -= lengthUnits_m[i].toAmountInBaseUnit(number);
		os << space(number && baseValue);
	}

	return os.str();
}
string CascadeFormate::space(bool flag) const
{
	if(flag) {
		return " ";
	} else {
		return "";
	}
}
CascadeFormate& CascadeFormate::getInstance()
{
	static CascadeFormate formater;

	return formater;
}

CascadeFormate::CascadeFormate()
{
}
